package com.woshua.vptabmodel.fragment;

import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.woshua.vptabmodel.R;

/**
 * @author Steven.zhao
 * email:hongtu.zhao@goodwinsoft.net
 * date:2019/7/20
 * desc:
 */
public class TabFragment extends Fragment {

    public static final  String FRAGMENT_TITLE_TAG="fragment_title_tag";

    private String title;
    private TextView tvTitle;

    public static TabFragment newInstance(String title)
    {
        Bundle bundle=new Bundle();
        bundle.putString(FRAGMENT_TITLE_TAG,title);
        TabFragment tabFragment=new TabFragment();
        tabFragment.setArguments(bundle);
        return tabFragment;
    }

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        final Bundle arguments = getArguments();
        if(arguments!=null)
        {
            title=arguments.getString(FRAGMENT_TITLE_TAG);
        }
    }

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        return inflater.inflate(R.layout.fragment_tab,container,false);
    }

    @Override
    public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);

        tvTitle = view.findViewById(R.id.tvTitle);
        tvTitle.setText(title);
    }

    public void changeTitle(String title)
    {
        if(!isAdded())
        {
            return;
        }
        tvTitle.setText(title);
    }
}
